public class test7 {
    public static void main(String[] args) {
        ListNode A = new ListNode(1);
        ListNode B = new ListNode(2);
        ListNode C = new ListNode(2);
        ListNode D = new ListNode(3);

        A.next = B;
        B.next = C;
        C.next = D;

        ListNode newHead = deleteDuplicates(A);
        while (newHead!=null) {
            System.out.println(newHead.val);
            newHead = newHead.next;
        }
    }

    public static ListNode deleteDuplicates(ListNode head) {
        // write code here
        // 尝试用两个指针
        // 如果出现两个指针相同的情况,就只动一个指针
        ListNode newHead = new ListNode();
        newHead.next = head;
        ListNode cur1 = newHead;
        ListNode cur2 = newHead;
        while (cur2!=null){
            if(cur2!=cur2.next) {
                cur1.next = cur2;
                cur1 = cur1.next;
                cur2 = cur2.next;
            }else{
                while (cur2==cur2.next&&cur2!=null){
                    // cur2 一直往后走
                    cur2 = cur2.next;
                }
                // 现在不相等了
                cur1.next = cur2.next;
            }
        }

        return newHead.next;
    }
}
